package org.example.wx.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.common.utils.ResponseUtil;
import org.example.db.entity.Goods;
import org.example.wx.service.WxCollectService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wx/collect")
@Api(tags = "收藏管理")
public class WxCollectController {

    WxCollectService wxCollectService;

    public WxCollectController(WxCollectService wxCollectService) {
        this.wxCollectService = wxCollectService;
    }

    @GetMapping("/is_collect")
    @ApiOperation("是否收藏")
    public Object isCollect(@RequestParam Long goodsId){

        int collect = wxCollectService.isCollect(goodsId);
        return ResponseUtil.ok(collect);
    }


    @GetMapping("/list")
    @ApiOperation("收藏列表")
    public Object list(){

        List<Goods> list = wxCollectService.list();

        return ResponseUtil.ok(list);
    }

    @PostMapping("/add")
    @ApiOperation("添加收藏")
    public Object add(@RequestBody Long goodsId){

        wxCollectService.add(goodsId);
        return ResponseUtil.ok();
    }


    @PostMapping("/delete")
    @ApiOperation("取消收藏")
    public Object delete(@RequestBody Long goodsId){

        wxCollectService.delete(goodsId);
        return ResponseUtil.ok();
    }
}
